package com.ys.timer;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;

import com.bo.util.DateUtil;
import com.ys.entity.amazonorder.TcoDayShop;
import com.ys.entity.business.TpAmazonShop;
import com.ys.entity.sys.TbStaticConfig;
import com.ys.service.amazonorder.TcoDayShopService;
import com.ys.service.business.TpAmazonShopService;

@Controller
public class TimerSettlePointReward {
    
    @Autowired
    private TcoDayShopService tcoDayShopService;

    /**
     * 日普品订单结算
     */
	@Scheduled(cron = "0 0 22 * * * ")
	public void updateTpAmazonShopOrderDaily() {
		
		BigDecimal baseNormal = new TbStaticConfig()
				.setKeyOne("point")
				.setKeyTwo("point-per-order-daily-normal")
				.queryFirst().getAmount();
		BigDecimal baseJingpin = new TbStaticConfig()
				.setKeyOne("point")
				.setKeyTwo("point-per-order-daily-jingpin")
				.queryFirst().getAmount();
		
		String today = DateUtil.getYYYY_MM_DD(new Date());
		
		List<TcoDayShop> listTcoDayShop = new TcoDayShop().setTimeDay(today).queryList();
		for(TcoDayShop entity : listTcoDayShop) {
			Long id = entity.getId();
			try {
				tcoDayShopService.settleShopOrderRewardPoint(id, baseNormal, baseJingpin);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
//		List<TpAmazonShop> listTpAmazonShop = new TpAmazonShop().where("A.FirstSaleDay is null")
//				.queryList();
//		
//		// 连续更新14天内的数据
//		for (TpAmazonShop entity : listTpAmazonShop) {
//			tpAmazonShopService.updateFirstSaleDay(entity.getGuid());
//		}
	}
	
}
